package com.cn.servlet.system;
import com.cn.Dao.DbOperateDao;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;



@WebServlet(name = "BackupServlet")
public class BackupServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String message="";
        request.setCharacterEncoding("GBK");
        response.setCharacterEncoding("GBK");
        try {
            DbOperateDao.doBackup();
            message="备份成功";
            System.out.println("备份成功");
            request.setAttribute("message",message);
            request.getRequestDispatcher("system_maintenance.jsp").forward(request, response);
        }catch (SQLException throwables) {
            throwables.printStackTrace();
            message="备份失败";
            System.out.println("备份失败");
            request.setAttribute("message",message);
            request.getRequestDispatcher("system_maintenance.jsp").forward(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            request.setAttribute("message", message);
        }
    }
}

